package C036;

/**
 * ClassName: C05
 * Package: C036
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/1/20 18:32
 * @Version 1.0
 * @Since 1.0
 */
public class C05 {
    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode5 = new TreeNode(5);
        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;
        treeNode2.left = treeNode4;
        treeNode3.right = treeNode5;
        System.out.println((minDepth(treeNode1)));
    }

    // 不提交这个类
    public static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public static int minDepth(TreeNode root) {
        if(root == null){
            return 0;
        }

        if(root.left == null && root.right == null){
            return 1;
        }
        int r = Integer.MAX_VALUE,l = Integer.MAX_VALUE;
        if(root.left != null){
            l = minDepth(root.left);
        }
        if(root.right != null){
            r = minDepth(root.right);
        }
        return 1 + Math.min(r, l);
    }
}
